package io.itit.ecp.admin.provide.selected;

import io.itit.ecp.admin.provide.action.resp.ActivityCarbonEmissionResp;
import io.itit.ecp.admin.server.entity.ActivityCarbonEmissionEntity;
import io.itit.ecp.admin.server.service.IActivityCarbonEmissionService;
import io.itit.grass.common.provide.action.resp.SelectedResp;
import io.itit.grass.common.server.selected.ISelected;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 活动碳排放管理
 */
@Component(ActivityCarbonEmissionSelected.CODE)
public class ActivityCarbonEmissionSelected implements ISelected<SelectedResp> {

    public static final String CODE = "ActivityCarbonEmissionSelected";

    @Resource
    private IActivityCarbonEmissionService activityCarbonEmissionService;

    @Override
    public String code() {
        return CODE;
    }

    @Override
    public List<SelectedResp> get(String param) {
        return activityCarbonEmissionService.lambdaQuery()
                .eq(ActivityCarbonEmissionEntity::getRelationDataOthers, Boolean.TRUE)
                .orderByAsc(ActivityCarbonEmissionEntity::getActivityName)
                .list()
                .stream()
                .map(t -> {
                    ActivityCarbonEmissionResp emissionResp = new ActivityCarbonEmissionResp();
                    emissionResp.setActivityType(t.getActivityType());
                    emissionResp.setId(t.getId());
                    emissionResp.setActivityName(t.getActivityName());
                    return SelectedResp.builder()
                            .label(t.getActivityName())
                            .baseObj(emissionResp)
                            .value(t.getId()).build();
                })
                .collect(Collectors.toList());
    }
}
